﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Lib.CommonForm;

namespace AUI
{
    public partial class frmUnitInfo : FormBase
    {
        int _UnitId = 0;
        DataRow m_dr;
        public frmUnitInfo(DataRow dr)
        {
            InitializeComponent();
            

            this.txtUnitCode.MaxLength = tbl_Units_Length.UnitCode;
            this.txtUnitName.MaxLength = tbl_Units_Length.UnitName;

            _listRole = tbl_RoleRight_Controller.Instance().GetInfo("DonViTinh");
            FormGlobals.Control_SetRequired(txtUnitCode, txtUnitName);
            m_dr = dr;
            if (m_dr != null)
            {
                FormGlobals.Panel_FillData(this, dr);
                _UnitId = Globals.ToInt32(dr["UnitId"]);
            }
            _IsLoading = false;
        }

        public override void Show_Form()
        {
            this.ShowDialog();
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            tbl_Units_Info i = new tbl_Units_Info();
            FormGlobals.Panel_GetData(this, i);
            i.UnitId = _UnitId;
            i.CreateUser = FormGlobals.strUserName;
            i.LastUser = FormGlobals.strUserName;

            txtUnitCode.BackColor = SystemColors.Window;
            if (tbl_Units_Controller.Instance().IsExist(i))
            {
                txtUnitCode.BackColor = Color.Yellow;
                FormGlobals.Message_Warning(lblUnitCode.Text + UIMessage.EXIST);
                txtUnitCode.Focus();
                return;
            }

            _UnitId = tbl_Units_Controller.Instance().Save(i);
            if (_UnitId > 0)
            {
                FormGlobals.Message_InTaskbar(UIMessage.SAVE_COMPLETE);
                _dlgResult = DialogResult.OK;
                this.Close();
            }
        }
    }
}
